package com.xq.springboot.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import com.xq.springboot.mapper.RoleMapper;
import com.xq.springboot.pojo.Role;
import com.xq.springboot.service.RoleService;

import java.util.ArrayList;
import java.util.List;

/**
 * @author xq
 * @date 2021/4/18 21:58
 * @version 1.0
 * @description 角色业务服务层接口实现层
 */
@Service
public class RoleServiceImpl implements RoleService{
    @Autowired
    private RoleMapper roleMapper;

    @Override
    public List<String> getRolesByUserId(Integer userId) {
        // 根据用户ID查询角色集合
        List<Role> rolesByUserId = this.roleMapper.getRolesByUserId(userId);
        List<String> roleNames = new ArrayList<>();
        for (Role role : rolesByUserId) {
            roleNames.add(role.getRoleName());
        }
        // 返回角色名称集合
        return roleNames;
    }
}
